/*
 * @Author: hucc
 * @Date: 2021-09-28 09:07:41
 * @LastEditors: hucc
 * @LastEditTime: 2021-09-28 15:31:02
 * @Description: 
 */

class Person {
    //静态属性 使用static来修饰
    static weight = '50kg'
        //实例属性 用构造器来声明
    constructor(name, age, gender) {
            this.name = name;
            this.age = age;
            this.gender = gender;
        }
        //实例方法  不需要任何关键字修饰 直接使用
    sayName() {
        console.log('my name is', this.name); //my name is tom
    }
    changeAge() {
            this.age++;
        }
        //静态方法 需要static关键字来修饰
    static sayWeight() {
        console.log(this.weight);
    }
}
//实例化
let tom = new Person('tom', 20, '男')
console.log(tom); //Person { name: 'tom', age: 20, gender: '男' }
tom.sayName();

tom.changeAge();
console.log(tom); //Person { name: 'tom', age: 21, gender: '男' }
//通过class类来调用静态属性和方法
//静态属性和方法只能由构造函数/class类来调用
console.log(Person.weight); //50kg
Person.sayWeight(); //50kg